package com.bkgy.modular.acidRolling.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.acidRolling.entity.AcidRillingC621;
import com.bkgy.modular.acidRolling.entity.AcidRillingC622;
import com.bkgy.modular.acidRolling.entity.Hottole;
import com.bkgy.modular.acidRolling.mapper.AcidRillingC622Mapper;
import com.bkgy.modular.acidRolling.mapper.AcidRillingMapper;
import com.bkgy.modular.acidRolling.service.AcidRillingService;
import com.bkgy.modular.qms.entity.QmsCurveDataMongo;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName AcidRillingServiceImpl
 * @date 2022/12/30 9:29
 */
@Service
public class AcidRillingServiceImpl extends ServiceImpl<AcidRillingMapper, AcidRillingC621> implements AcidRillingService{

    @Resource
    private MongoTemplate mongoTemplate;

    @Resource
    private AcidRillingMapper acidRillingMapper;

    @Resource
    private AcidRillingC622Mapper acidRillingC622Mapper;

    /**
     * 1720酸轧和2130酸轧的原料弹窗mongdb查询结果
     * @param volumeNo
     * @return
     */
    @Override
    public ResultData findByMongoDBData(String volumeNo) {
        if (!StringUtils.hasText(volumeNo)) {
            return ResultData.ResultDataFaultSelf(null, "传入卷号为空");
        }
        // 创建查询条件
        Query query = new Query(Criteria.where("volumeNo").is(volumeNo));
        List<QmsCurveDataMongo> list = mongoTemplate.find(query, QmsCurveDataMongo.class);

        Map<String,Object> map = new HashMap<>();
        // 遍历集合
        for (QmsCurveDataMongo item : list) {
            Map<String,Object> mongodbMap = new HashMap<>();
            // item.getOriginBolg()为null 跳出当前循环
            if (item.getOriginBolg() == null) {
                map.put("mongodbMap",mongodbMap);
            } else  {
                List<Double> hsm_fdh_thk_cold = item.getOriginBolg().get("hsm_fdh_thk_cold");
                List<Double> hsm_fdw_width_cold = item.getOriginBolg().get("hsm_fdw_width_cold");
                List<Double> hsm_ctc_ct_temp = item.getOriginBolg().get("hsm_ctc_ct_temp");
                List<Double> hsm_fdt_fdt = item.getOriginBolg().get("hsm_fdt_fdt");
                List<Double> hsm_flatness_symmetric_flatness = item.getOriginBolg().get("hsm_flatness_symmetric_flatness");
                List<Double> hsm_flatness_asymmetric_flatness = item.getOriginBolg().get("hsm_flatness_asymmetric_flatness");
                List<Double> hsm_flatness_wedge40 = item.getOriginBolg().get("hsm_flatness_wedge40");
                List<Double> hsm_crown_c40 = item.getOriginBolg().get("hsm_crown_c40");

                mongodbMap.put("hsm_fdh_thk_cold",hsm_fdh_thk_cold);
                mongodbMap.put("hsm_fdw_width_cold",hsm_fdw_width_cold);
                mongodbMap.put("hsm_ctc_ct_temp",hsm_ctc_ct_temp);
                mongodbMap.put("hsm_fdt_fdt",hsm_fdt_fdt);
                mongodbMap.put("hsm_flatness_symmetric_flatness",hsm_flatness_symmetric_flatness);
                mongodbMap.put("hsm_flatness_asymmetric_flatness",hsm_flatness_asymmetric_flatness);
                mongodbMap.put("hsm_flatness_wedge40",hsm_flatness_wedge40);
                mongodbMap.put("hsm_crown_c40",hsm_crown_c40);
            }
            map.put("mongodbMap",mongodbMap);
        }

        // 构建查询条件C621
        LambdaQueryWrapper<AcidRillingC621> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AcidRillingC621::getHot_coil_id,volumeNo);
        List<AcidRillingC621> acidRillingC621List = acidRillingMapper.selectList(queryWrapper);
        map.put("1720acidRillingList", acidRillingC621List);


        // 构建查询条件C622
        LambdaQueryWrapper<AcidRillingC622> queryWrapper2 = new LambdaQueryWrapper<>();
        queryWrapper2.eq(AcidRillingC622::getHot_coil_id,volumeNo);
        List<AcidRillingC622> acidRillingC622ListList = acidRillingC622Mapper.selectList(queryWrapper2);
        map.put("2130acidRillingList", acidRillingC622ListList);

        return ResultData.ResultDataFaultSelf("操作成功",map);
    }

    @Override
    public ResultData findMongdb(String volumeNo) {
        if (!StringUtils.hasText(volumeNo)) {
            return ResultData.ResultDataFaultSelf(null, "传入卷号为空");
        }
        // 创建查询条件
        Query query = new Query(Criteria.where("volumeNo").is(volumeNo));
        Hottole hottole = mongoTemplate.findOne(query, Hottole.class);
        return ResultData.ResultDataFaultSelf("操作成功",hottole);
    }
}
